package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.LeaseTerm;
import com.atguigu.lease.web.admin.service.LeaseTermService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/term")
@Tag(name = "租期管理！(LeaseTermController)")
public class LeaseTermController {

    @Autowired
    private LeaseTermService service;

    @PostMapping("/saveOrUpdate")
    @Operation(summary = "保存或更新租期信息")
    public Result saveOrUpdate(@RequestBody LeaseTerm leaseTerm) {
        boolean b = service.saveOrUpdate(leaseTerm);
        return b ? Result.ok() : Result.fail();
    }

    @GetMapping("/list")
    @Operation(summary = "查询全部租期列表")
    public Result<List<LeaseTerm>> getAll() {
        List<LeaseTerm> list = service.list();
        return Result.ok(list);
    }

    @DeleteMapping("/deleteById")
    @Operation(summary = "根据ID删除租期")
    public Result deleteById(@RequestParam Long id) {
        boolean b = service.removeById(id);
        return b ? Result.ok() : Result.fail();
    }

}
